import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2024-05-05
 * Time: 16:15
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextInt();
        long p = scanner.nextInt();
        System.out.println(fastPow(n, p - 2, p));
    }

    private static long fastPow(long num, long p, long mod) {
        long res = 1;
        while (p != 0) {
            if ((p & 1) != 0) {
                res *= num;
                res %= mod;
            }
            num *= num;
            num %= mod;
            p >>= 1;
        }
        return res;
    }
}
